using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using ShopForWeb.UI.Models.Test;

namespace ShopForWeb.UI.Controllers.Test
{
  //写请求或网址书写习惯一律小写
 [Route("test/[controller]")]
  public class UserController : Controller
  {

  public UserController()
  {

  }

  [HttpGet("{userId}")]
  public IActionResult GetUser([FromRoute] string userId)
 {
      UserModel u=new UserModel()
   {
      UserId="1",
      Age=28,
      Sex="男",
      Address="山东省烟台市"
   };
   ViewBag.User=u;
   return View("~/Views/Test/User/GetUser.cshtml");
 }

    [HttpGet("age")]
    public IActionResult GetUser([FromQuery] int age)
{
   object user1 = new
{
    Name = "张三",
    Sex = "男",
    Age = age
};
    IList result = new ArrayList() { user1 };
    return Json(result);
 }

    [HttpDelete("{userId}")]
    public IActionResult RemoveUser([FromRoute] string userId)
 {
    return Json(new
 {
     Message = $"{userId}-删除成功"
});
 }
[HttpPost]
 public IActionResult AddUser([FromForm]UserModel user)
 {
   return Json(new
   {
      Message="添加成功",
      user=user
   });
 }
 [HttpPut]
public IActionResult ModifyUser([FromBody]UserModel user)
 {
   return Json(new
   {
      Message="修改成功",
      user=user
   });
 }

public IActionResult Index()
{
   List<UserModel>list =new List<UserModel>();
      UserModel u=new UserModel()
   {
      UserId="1",
      Age=28,
      Sex="男",
      Address="山东省烟台市"
   };
   list.Add(u);
   ViewBag.UserList=list;
   return View("~/Views/Test/User/Index.cshtml");

}
 }}